Welcome to Sophie Nickerson's C# Programming Primer!

This is a website where you will learn the basics about programming in C#

Console Output Windows Output Declare and Initialize Variables

Brief Overview of C#

C# is an easy to learn, modern language created by Microsoft. It is a general purpose programming language, and is both object and component oriented. C# is a structured language and produces efficient programs.

How to Create a Program

Console Program:

  1. Select Console Application
  2. Console.WriteLine(“text”);
  3. Console.ReadLine();
  4. Press start to run program

Windows Form Program:

  1. Select Windows Forms Application
  2. Drag a button onto form
  3. Double-click the button and add code:
  4. MessageBox.Show(“text”);

How to Create an Output

Console Output:

  1. Select Console Application
  2. Console.WriteLine(“text”);
  3. Console.ReadLine();
  4. Press start to run program
Top of Page

Top of Page

Windows Output

example with label and richtextbox

  1. Select Windows Form Application
  2. Drag a button and name it btnAnything
  3. Change the Text to anything you want
  4. Double click the button
  5. Enter code:
  6. lblAnything.Text = “text”;
  7. rtbAnything.Text = “text”;
  8. Press start to run program
Top of Page

Top of Page

How to Declare and Initialize Variables

Boolean Variables

  1. Boolean variables only store two values: True or False
  2. To declare a Boolean Variable
  3. To Initialize a Boolean Variable

Integer Variables

  1. Integers are useful for counting and keeping track of numbers without decimals
  2. To declare an Integer Variable
  3. To initialize an Integer Variable

Floating Point (Double, or decimal)

  1. If dealing with fractions or decimals use a floating point. The most common data type to use is a Double.
  2. To declare a Double Variable
  3. To initialize a Double Variable

String Variables

  1. If not using variable to do math, or you want to represent words use String variables. Strings can be any combination of letters, numbers, or punctuation marks.
  2. To declare a String Variable
  3. To initialize a String Variable

Note: Declaring and Initializing Variables

You can also declare and initialize a variable in one statement of code

Top of Page